<script setup>
import { ArrowRightBold } from '@element-plus/icons-vue'
import { ref } from 'vue'
const List = ref([
  { id: 1, name: '手机' },
  { id: 2, name: '电视' },
  { id: 3, name: '家电' },
  { id: 4, name: '笔记本 平板' },
  { id: 5, name: '出行 穿戴' },
  { id: 6, name: '耳机 音箱' },
  { id: 7, name: '健康 儿童' },
  { id: 8, name: '生活 箱包' },
  { id: 9, name: '智能 路由器' },
  { id: 10, name: '电源 配件' }
])
const goods = ref([
  {
    id: 1,
    name: 'XiaoMi MiX系列',
    img: 'https://www.mi.com/shop/buy?product_id=1230800650&cfrom=search'
  }
])
</script>

<template>
  <div class="home-category">
    <ul class="menu">
      <li v-for="item in List" :key="item.id">
        <RouterLink to="/">{{ item.name }}</RouterLink>
        <span>
          <el-icon color="#fff"><ArrowRightBold /></el-icon
        ></span>
        <!-- 弹层layer位置 -->
        <div class="layer">
          <ul>
            <li v-for="i in goods" :key="i.id">
              <RouterLink to="/">
                <img :src="i.picture" alt="" />
                <div class="info">
                  <p class="name ellipsis-2">{{ i.name }}</p>
                  <img :src="i.img" />
                </div>
              </RouterLink>
            </li>
          </ul>
        </div>
      </li>
    </ul>
  </div>
</template>

<style scoped lang="scss">
.home-category {
  width: 234px;
  height: 550px;
  background: rgba(105, 101, 101, 0.6);
  position: relative;
  z-index: 99;

  .menu {
    li {
      display: flex;
      justify-content: space-between;
      padding-left: 40px;
      height: 55px;
      line-height: 55px;

      &:hover {
        background: #ff7300;
      }

      a {
        margin-right: 4px;
        color: #fff;

        &:first-child {
          font-size: 14px;
        }
      }
      span {
        margin-right: 20px;
      }

      .layer {
        width: 990px;
        height: 500px;
        background: rgba(255, 255, 255, 0.8);
        position: absolute;
        left: 250px;
        top: 0;
        display: none;
        padding: 0 15px;

        h4 {
          font-size: 20px;
          font-weight: normal;
          line-height: 80px;

          small {
            font-size: 16px;
            color: #666;
          }
        }

        ul {
          display: flex;
          flex-wrap: wrap;

          li {
            width: 310px;
            height: 120px;
            margin-right: 15px;
            margin-bottom: 15px;
            border: 1px solid #eee;
            border-radius: 4px;
            background: #fff;

            &:nth-child(3n) {
              margin-right: 0;
            }

            a {
              display: flex;
              width: 100%;
              height: 100%;
              align-items: center;
              padding: 10px;

              &:hover {
                background: #e3f9f4;
              }

              img {
                width: 95px;
                height: 95px;
              }

              .info {
                padding-left: 10px;
                line-height: 24px;
                overflow: hidden;

                .name {
                  font-size: 16px;
                  color: #666;
                }

                .desc {
                  color: #999;
                }

                .price {
                  font-size: 22px;
                  color: #ff7300;

                  i {
                    font-size: 16px;
                  }
                }
              }
            }
          }
        }
      }

      // 关键样式  hover状态下的layer盒子变成block
      &:hover {
        .layer {
          display: block;
        }
      }
    }
  }
}
</style>
